/
<template>
  <div>
    <el-dialog
      title="提示"
      :visible="dialogVisible"
      width="50%"
      :show-close="true"
      :before-close="handleClose"
      :destroy-on-close="true"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="key">
          <el-input v-model="form.key"></el-input>
        </el-form-item>
        <el-form-item label="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="age">
          <el-input v-model="form.age"></el-input>
        </el-form-item>
        <el-form-item label="img">
          <template>
            <el-image lazy :src="form.img"></el-image>
          </template>
        </el-form-item>
        <el-form-item label="address">
          <el-input v-model="form.address"></el-input>
        </el-form-item>
        <el-form-item label="price">
          <el-input v-model="form.price"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button @click="handleDialogClose">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { mapMutations } from "vuex";
export default {
  data() {
    return {
      form: {
        id: "",
        key: "",
        name: "",
        age: "",
        img: "",
        address: "",
      },
    };
  },
  watch: {
    edit_value: "set_form",
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: true,
    },
    handleDialogClose: {
      type: Function,
      default: () => {},
    },
    edit_value: {
      type: Object,
      default: () => {},
    },
  },
  methods: {
    ...mapMutations("table_reducer", ["edit_table_data"]),
    set_form() {
      this.form = this.edit_value;
    },
    onSubmit() {
      console.log("submit!", this.form);
      this.edit_table_data(this.form);
      this.handleDialogClose();
    },
  },
};
</script>

<style></style>
